unit TwoRptOption;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Edit, RzPanel, ExtCtrls, RzDlgBtn, StdCtrls, Mask, RzEdit,
  RzLabel, DateUtils;

type
  TTwoRptOptionFrm = class(TEditFrm)
    dtFrom: TRzDateTimeEdit;
    dtTo: TRzDateTimeEdit;
    RzLabel1: TRzLabel;
    RzLabel2: TRzLabel;
    dmFrom: TRzDateTimeEdit;
    RzLabel3: TRzLabel;
    RzLabel4: TRzLabel;
    dmTo: TRzDateTimeEdit;
    procedure RzDialogButtons1ClickCancel(Sender: TObject);
    procedure RzDialogButtons1ClickOk(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  TwoRptOptionFrm: TTwoRptOptionFrm;

implementation

uses DM;

{$R *.dfm}


procedure TTwoRptOptionFrm.RzDialogButtons1ClickCancel(Sender: TObject);
begin
  inherited;
  Close;
end;

procedure TTwoRptOptionFrm.RzDialogButtons1ClickOk(Sender: TObject);
var
  dtStart, dtEnd: Tdatetime;
  AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word;
begin
  inherited;
  try
    dtStart := dtFrom.Date;
    dtEnd := dtTo.Date;
    DecodeDateTime(dmFrom.Time,AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond);
    AYear  := YearOf(dtStart);
    AMonth := MonthOf(dtStart);
    ADay :=  DayOf(dtStart);
    dtStart := EncodeDateTime(AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond);


    DecodeDateTime(dmTo.Time,AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond);
    AYear  := YearOf(dtEnd);
    AMonth := MonthOf(dtEnd);
    ADay :=  DayOf(dtEnd);
    dtEnd := EncodeDateTime(AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond);


    dmMain.TwoMeterRpt.Close;
    dmMain.TwoMeterRpt.SQL.Clear;
    dmMain.TwoMeterRpt.SQL.Add('Select *, SaveDate  As SaveTime  from TwoMeter where  (SaveDate >=:@BeginDate) AND (SaveDate <= :@EndDate)');
    dmMain.TwoMeterRpt.Parameters.ParamByName('@BeginDate').Value := dtStart;
    dmMain.TwoMeterRpt.Parameters.ParamByName('@EndDate').Value := dtEnd;
    dmMain.TwoMeterRpt.Open;    
  except


  end;
end;

procedure TTwoRptOptionFrm.FormShow(Sender: TObject);
var
  dmTime: TDateTime;
begin
  inherited;
  dmTime := Now;
  dmFrom.Time := IncMinute( TimeOf(dmTime),-30);
  dmTo.Time := TimeOf(dmTime);
  dtFrom.Date := Date;
  dtTo.Date := Date;
end;

end.
